package com.irdstudio.bhcredit.console.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.bhcredit.console.dao.PluginServiceParamDao;
import com.irdstudio.bhcredit.console.dao.domain.PluginServiceParam;
import com.irdstudio.bhcredit.console.service.api.PluginServiceParamService;
import com.irdstudio.bhcredit.console.service.vo.PluginServiceParamVO;
import com.irdstudio.ssm.framework.service.FrameworkService;
/**
 * <p>ServiceImpl: 服务参数配置				<p>
 * @author ligm
 * @date 2019-02-18
 */
@Service("pluginServiceParamServiceImpl")
public class PluginServiceParamServiceImpl implements PluginServiceParamService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PluginServiceParamServiceImpl.class);

	@Autowired
	private PluginServiceParamDao pluginServiceParamDao;
	
	/**
	 * 新增操作
	 */
	public int insertPluginServiceParam(PluginServiceParamVO inPluginServiceParamVo) {
		logger.debug("当前新增数据为:"+ inPluginServiceParamVo.toString());
		int num = 0;
		try {
			PluginServiceParam pluginServiceParam = new PluginServiceParam();
			beanCopy(inPluginServiceParamVo, pluginServiceParam);
			num = pluginServiceParamDao.insertPluginServiceParam(pluginServiceParam);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PluginServiceParamVO inPluginServiceParamVo) {
		logger.debug("当前删除数据条件为:"+ inPluginServiceParamVo);
		int num = 0;
		try {
			PluginServiceParam pluginServiceParam = new PluginServiceParam();
			beanCopy(inPluginServiceParamVo, pluginServiceParam);
			num = pluginServiceParamDao.deleteByPk(pluginServiceParam);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPluginServiceParamVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PluginServiceParamVO inPluginServiceParamVo) {
		logger.debug("当前修改数据为:"+ inPluginServiceParamVo.toString());
		int num = 0;
		try {
			PluginServiceParam pluginServiceParam = new PluginServiceParam();
			beanCopy(inPluginServiceParamVo, pluginServiceParam);
			num = pluginServiceParamDao.updateByPk(pluginServiceParam);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPluginServiceParamVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PluginServiceParamVO queryByPk(PluginServiceParamVO inPluginServiceParamVo) {
		
		logger.debug("当前查询参数信息为:"+ inPluginServiceParamVo);
		try {
			PluginServiceParam queryPluginServiceParam = new PluginServiceParam();
			beanCopy(inPluginServiceParamVo, queryPluginServiceParam);
			PluginServiceParam queryRslPluginServiceParam = pluginServiceParamDao.queryByPk(queryPluginServiceParam);
			if (Objects.nonNull(queryRslPluginServiceParam)) {
				PluginServiceParamVO outPluginServiceParamVo = beanCopy(queryRslPluginServiceParam, new PluginServiceParamVO());
				logger.debug("当前查询结果为:"+ outPluginServiceParamVo.toString());
				return outPluginServiceParamVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PluginServiceParamVO> queryAllOwner(PluginServiceParamVO pluginServiceParamVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PluginServiceParamVO> list = null;
		try {
			List<PluginServiceParam> pluginServiceParams = pluginServiceParamDao.queryAllOwnerByPage(pluginServiceParamVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pluginServiceParams.size());
			pageSet(pluginServiceParams, pluginServiceParamVo);
			list = (List<PluginServiceParamVO>) beansCopy(pluginServiceParams, PluginServiceParamVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PluginServiceParamVO> queryAllCurrOrg(PluginServiceParamVO pluginServiceParamVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PluginServiceParam> pluginServiceParams = pluginServiceParamDao.queryAllCurrOrgByPage(pluginServiceParamVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pluginServiceParams.size());
		List<PluginServiceParamVO> list = null;
		try {
			pageSet(pluginServiceParams, pluginServiceParamVo);
			list = (List<PluginServiceParamVO>) beansCopy(pluginServiceParams, PluginServiceParamVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PluginServiceParamVO> queryAllCurrDownOrg(PluginServiceParamVO pluginServiceParamVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PluginServiceParam> pluginServiceParams = pluginServiceParamDao.queryAllCurrDownOrgByPage(pluginServiceParamVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pluginServiceParams.size());
		List<PluginServiceParamVO> list = null;
		try {
			pageSet(pluginServiceParams, pluginServiceParamVo);
			list = (List<PluginServiceParamVO>) beansCopy(pluginServiceParams, PluginServiceParamVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}
}
